package com.yamin.picToCharPaint.service;

import com.yamin.picToCharPaint.utils.image.IPicToStrPic;
import com.yamin.picToCharPaint.utils.image.ImageConfig;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @description:
 * @author：yamin
 * @date: 2021/9/15
 */
@Service
public class ImageService extends ImageConfig {

    public void invertImg(MultipartFile file, int precision) {
        String filename = file.getOriginalFilename();
        assert filename != null;
        String formatName = filename.split("\\.")[1];
        formatName = formatName.toLowerCase();
        IPicToStrPic strPic = utilMap.get(formatName);
        try {
            InputStream inputStream = file.getInputStream();
            strPic.toStrPic(inputStream, precision, formatName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
